// pages/post/post.js
const app = getApp()
const db = wx.cloud.database()

Page({
  onTapJumpXiadan: function (event) {
    wx.navigateTo({
      url: '../xiadan/xiadan',
      success: function () {
        console.log("jump success")
      },
      fail: function () {
        console.log("jump failed")
      },
      complete: function () {
        console.log("jump complete")
      }
    })
  },

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      "http://qvg7sznun.hn-bkt.clouddn.com/1.png",
      "http://qvg7sznun.hn-bkt.clouddn.com/22.jpg",
      "http://qvg7sznun.hn-bkt.clouddn.com/3.png"
    ],
    allPostData: [],
    

  },
   jumpToPostDetail: function (e) {
    console.log("页面跳转前传递的物件id",e.currentTarget.dataset.id)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/post-detail/post-detail?id='+id,
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this
    
    db.collection('allPostData')
    .get({
      success:function(res){
        console.log(res.data[0].allPostData)
        that.setData({
          allPostData: res.data[0].allPostData
        })
      }
    })
  },

  navigateToShop: function(event) {
    
    console.log(event.currentTarget.dataset.item.postId)
    console.log(event.currentTarget.dataset.item.pic)
    getApp().globalData.cate_id = event.currentTarget.dataset.item.postId-1
    getApp().globalData.cate_toView = event.currentTarget.dataset.item.pic
    // console.log("cate_id=",getApp().globalData.cate_id)
    // console.log("cate_toView=",getApp().globalData.cate_toView)

    wx.switchTab({
      url: '../category/category',
    })
  },

  navigateToShop1: function(event) {
    
    console.log(event.currentTarget.dataset.item.postId)
    console.log(event.currentTarget.dataset.item.pic)
    // getApp().globalData.cate_id = event.currentTarget.dataset.item.id-1
    // getApp().globalData.cate_toView = event.currentTarget.dataset.item.pic
    var id =  event.currentTarget.dataset.item.postId-1
    var pic = event.currentTarget.dataset.item.pic
    
    wx.reLaunch({
      url: '../category/category?cate_id='+id +"&cate_toView="+pic,
    })
  },


  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})